<?php

class Evento extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('model_evento_instalacion_deportiva/evento_model');
    }
	
	// Cargar view calendario 
	    function evento_instalaciones() {
        $session_id = $this->session->userdata('is_logued_in');
        if ($session_id) {
            $this->load->view('view_eventos_instalaciones_deportivas/view_evento');
        } else {
            $data['contenido'] = 'login_view';
            $this->load->view('plantillas/plantilla', $data);
            $this->session->unset_userdata('is_logued_in');
        }
    }
	

    //Guardar un nuevo evento   
    function save() {
        echo "Estoy aki";

        $id = $this->input->get('id');
        $start = $this->input->get('start');
        $title = $this->input->get('title');
        $body = $this->input->get('body');
        $end = $this->input->get('end');
        $tipoInstalacion = $this->input->get('tipoInstalacion');

        echo $id;
        $idEvento = $this->evento_model->save($id, $start, $end, $title, $body, $tipoInstalacion);

        echo $idEvento;
    }
//fin
//
    //Obtner el max registro almacenado en la base   
    function get_count() {

        $res = $this->evento_model->get_count();

        foreach ($res as $i => $fila) {
            $id = $fila->id;
        }
        echo $id;
    }

    
    //Obtener los eventos actuales almacenado segun la instalacion
    
    function get_events(){
        
         $tipoInstalacion=$this->input->get('tipoInstalacion'); 
         $eventos =$this->evento_model->get_events($tipoInstalacion);
         echo '{"events":'.json_encode($eventos).'}'; 
        
    }
    
    
    //Eliminar un evento 

    function delete() {
        $id = $this->input->get('id');
        $this->evento_model->delete($id);
    }

    
    
    function move() {
        $id = $this->input->get('id');
        $start = $this->input->get('start');
        $end = $this->input->get('end');

        $this->evento_model->move($id, $start, $end);
    }

    
    function update() {

        $id = $this->input->get('id');
        $start = $this->input->get('start');
        $end = $this->input->get('end');
        $title = $this->input->get('title');
        $body = $this->input->get('body');

        $this->evento_model->update($id, $start, $title, $end, $body);
    }

}

